import Vue from 'vue'
import App from './App.vue'
import router from './router'
import 'lib-flexible'
import Vant from 'vant'
import 'vant/lib/index.css'
import store from './store'
import SvgIcon from '@/components/SvgIcon'
import navBar from '@/components/navBar'
import { sync } from 'vuex-router-sync'
import '@/permission' // permission control

import echarts from '@/utils/echarts'
Vue.prototype.$echarts = echarts

import { DevConfig, nativeHandler } from 'qmp-native'
DevConfig.useDefaultData = !(process.env.NODE_ENV === 'production')
if (process.env.NODE_ENV !== 'production') {
  // web测试环境调试配置
  DevConfig.defaultData = {
    '': {
      token: 'Bearer b4f5823c-ddfc-425e-bbf2-c5f6ae314067'
    },
    // nativeHandler('getBaseInfo') 接口在测试环境返回的数据
    getBaseInfo: {
      account: 'test1',
      userName: 'test1'
    },
    // 调用原生其他接口 返回的数据
    default: {
      property1: 'value1',
      property2: 'value2'
    }
  }
}

Vue.prototype.$nativeHandler = nativeHandler
window.nativeHandler = nativeHandler

Vue.config.productionTip = false

Vue.filter('filterForamtThousand', (num) => {
  if (Number(num || 0) === 0) return 0
  return (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,')
})

Vue.prototype.foramtThousand = (num) => {
  if (Number(num || 0) === 0) return 0
  return (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,')
}

// 打开指标说明
Vue.prototype.openInstrusction = (code, type) => {
  store.commit('updateIntroData', { code, type, show: true })
}

Vue.use(Vant)
Vue.component('nav-bar', navBar)
Vue.component('svg-icon', SvgIcon)
sync(store, router)

new Vue({
  router,
  store,
  render: (h) => h(App)
}).$mount('#app')
